home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWDebug / Include / FWPriDeb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  3.9 KB  |  147 lines  |  [TEXT/MPS ]

  1. #ifndef FWPRIDEB_H
  2. #define FWPRIDEB_H
  3. //========================================================================================
  4. //
  5. //    File:                FWPriDeb.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #ifdef FW_DEBUG
  15.  
  16. #ifndef FWDBGSTR_H
  17. #include "FWDbgStr.h"
  18. #endif
  19.  
  20. class FW_CDebugConsole
  21. {
  22. public:
  23.  
  24.     virtual ~FW_CDebugConsole();
  25.         // Destructor, does nothing.
  26.     
  27.     FW_CDebugConsole();
  28.         // Constructor, does SetConsole(0).
  29.  
  30.     static FW_CDebugConsole* GetConsole();
  31.         // Get the currently installed debug console
  32.         
  33.     static FW_CDebugConsole* SetConsole(FW_CDebugConsole* console);
  34.         // Install a new debug console.
  35.         // The prior debug console is returned.
  36.  
  37.     static void LogMessage(const char* message);
  38.         // Display the message, preferably without suspending execution.
  39.         
  40.     static void DebugMessage(const char* message);
  41.         // Suspend normal execution and display the message.
  42.         
  43.     static void Debugger();
  44.         // Suspend normal execution without displaying a message
  45.     
  46.     FW_CDebugStream & GetFatalErrorStream();
  47.         // Get the fatal error stream
  48.     
  49.     FW_CDebugStream & GetWarningStream();
  50.         // Get the warning stream
  51.     
  52.     FW_CDebugStream & GetNotificationStream();
  53.         // Get the notification stream
  54.     
  55. protected:
  56.  
  57.     virtual void DoLogMessage(const char* message);
  58.         // Display the message, preferably without suspending execution.
  59.         
  60.     virtual void DoDebugMessage(const char* message);
  61.         // Suspend normal execution and display the message.
  62.         
  63.     virtual void DoDebugger();
  64.         // Suspend normal execution without displaying a message
  65.  
  66.     FW_CDebugStream * fFatalErrorStream;
  67.         // Stream for fatal error messages
  68.  
  69.     FW_CDebugStream * fWarningStream;
  70.         // Stream for warning messages
  71.  
  72.     FW_CDebugStream * fNotificationStream;
  73.         // Stream for notification messages
  74.  
  75. public:
  76.  
  77.     // ----- Internal Methods
  78.  
  79.     static void PrivDebugMessage(const char* message);
  80.         // Hard drop into debugger and display the message.
  81.         
  82.     static void PrivDebugger();
  83.         // Hard drop into debugger without displaying a message
  84.         
  85. private:
  86.     enum { kBufferSize = 100};
  87.         // Size of the buffer for the debug stream
  88.     
  89.     char fBuffer[100];
  90.         // The debug stream buffer
  91.  
  92.     FW_CBufferDebugStream fBufferStream;
  93.         // Buffer stream
  94.         
  95.     FW_CNullDebugStream fNullStream;
  96.         // Null stream
  97.         
  98.     FW_CDebugConsole(const FW_CDebugConsole& debugConsole);
  99.     FW_CDebugConsole& operator=(const FW_CDebugConsole& debugConsole);
  100.         // Don't copy instances of this class.
  101. };
  102.  
  103. #define FW_PRIV_DEBUGGER_BREAK() FW_CDebugConsole::PrivDebugger()
  104.  
  105. #define FW_PRIV_DEBUGGER_STRING(message) FW_CDebugConsole::PrivDebugMessage(message)
  106.  
  107. #define FW_PRIV_ASSERT(f) if(!(f)) FW_CDebugConsole::PrivDebugMessage((const char*) #f)
  108.     // If f evaluates to false, drop into the debugger and display f as string.
  109.  
  110. #define FW_DEBUGGER() FW_CDebugConsole::Debugger()
  111.  
  112. #define FW_DEBUG_MESSAGE(message) FW_CDebugConsole::DebugMessage(message)
  113.  
  114. #define FW_LOG_MESSAGE(message) FW_CDebugConsole::LogMessage(message)
  115.  
  116. #define FW_ASSERT(f) if(!(f)) FW_CDebugConsole::DebugMessage((const char*) #f)
  117. //#define FW_ASSERT(f) if(!(f)) FW_CDebugConsole::DebugMessage((const char*) #f)
  118.     // If f evaluates to false, drop into the debug console and display f as string.
  119.  
  120. inline FW_CDebugStream & FW_CDebugConsole::GetFatalErrorStream()
  121. {
  122.     return *fFatalErrorStream;
  123. }
  124.  
  125. inline FW_CDebugStream & FW_CDebugConsole::GetWarningStream()
  126. {
  127.     return *fWarningStream;
  128. }
  129.  
  130. inline FW_CDebugStream & FW_CDebugConsole::GetNotificationStream()
  131. {
  132.     return *fNotificationStream;
  133. }
  134.  
  135. #else
  136.  
  137. #define FW_PRIV_DEBUGGER_BREAK() ((void)0)
  138. #define FW_PRIV_DEBUGGER_STRING(message) ((void)0)
  139. #define FW_PRIV_ASSERT(f) ((void)0)
  140. #define FW_DEBUGGER() ((void)0)
  141. #define FW_DEBUG_MESSAGE(message) ((void)0)
  142. #define FW_LOG_MESSAGE(message) ((void)0)
  143. #define FW_ASSERT(f) ((void)0)
  144.  
  145. #endif
  146.  
  147. #endif